#ifndef _QUEST_HANDLER_H
#define _QUEST_HANDLER_H


struct Quest
{
	ui32 entry;
	ui32 minlevel;
	char* title, *main_text, *end_text, *objectives, *completion, *objectives1, *objectives2, *objectives3, *objectives4;
	ui32 requirednpc[4], requirednpccount[4];
	ui32 requireditem[4], requireditemcount[4];
	ui32 point_mapid, point_x, point_y, point_opt;
	ui32 rewardchoice[6], rewardchoicecount[6];
	ui32 rewardfix[4], rewardfixcount[4];
	ui32 rewardtalents, rewartitle, reward_money;
	ui32 players_to_kill, flags, srcitem, questlevel, needed_players;
	ui32 questtype, zoneid, questsort, required_faction, required_reputation;
	ui32 required_money, casted_spell, rewarded_honor, learned_spell;
	ui32 preq1, preq2, preq3, preq4, preq5, preq6;

	ui32 GetNumRewardChoice()
	{
		ui32 count = 0;
		for(int i = 0; i < 6; ++i)
			count += rewardchoicecount[i];
		return count;
	}
	ui32 GetNumReward()
	{
		ui32 count = 0;
		for(int i = 0; i < 4; ++i)
			count += rewardfixcount[i];
		return count;
	}
};

struct NPCQuestStart
{
	ui32 entry;
	set<ui32> questentries;
};

class QuestHandler : public Single<QuestHandler>
{
	friend class World;
	void LoadQuestRelations();
	stdext::hash_map<ui32, NPCQuestStart*> NPCQuestStartStorage;
public:
	ui8 CalculateQuestStatus(ui32 questentry, Player* pPlayer);
	NPCQuestStart* GetStartingRelation(ui32 npcentry) { return NPCQuestStartStorage[npcentry]; }
	ui8 GetAvailableQuests(set<ui32>& quests, Player* target);
	void UpdateNearbyQuestgivers(Player* target);
};

#define sQuestHandler (*(QuestHandler::getSingle()))

#endif